package com.wlq;

import com.wlq.client.ClientHandler;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.IOException;
import java.io.InputStream;
import java.net.ServerSocket;
import java.net.Socket;

/**
 * @Description:
 * @Auther: wlq
 * @Date: 2022/7/24 13:02
 */
public class WebBoot {

    private static final Logger logger =LoggerFactory.getLogger(WebBoot.class);

    private ServerSocket serverSocket;

    public WebBoot( ) {
        logger.info("web容器正在启动...");
        try {
            serverSocket = new ServerSocket(8087);
            logger.info("web容器启动完毕...");
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    /**
     * 容器启动后等待客户端链接的方法
     */
    public void link(){
        try {
            Socket socket = serverSocket.accept();

            //如果客户端链接,创建处理客户端对象
            ClientHandler clientHandler = new ClientHandler(socket);
            Thread t = new Thread(clientHandler);
            t.start();


        } catch (IOException e) {
            e.printStackTrace();
        }

    }

    public static void main(String[] args) {
        WebBoot webBoot = new WebBoot();
        webBoot.link();
    }

}
